
function onContinue( nextSection_ )
{
	$.fancybox.showLoading();
	var nextSection = nextSection == null ? 2: nextSection_;		
	loader.load( nextSection, $( '#form' ).serializeObject() );
}

function onLoadSection()
{
	$.fancybox.hideLoading();

	mamba.init(
		function () 
		{			
			var userId = getUrlParam( 'oid' );
			var sid = getUrlParam( 'sid' );

			mamba.api(
				{
					method: "contacts.getContactList"
				},
				function( err, data )
				{

					//[ 'data' ][ 'contacts' ][ 'message_count' ];
					//[ 'data' ][ 'contacts' ][ 'square_photo_url' ];

					
					var contacts = data[ 'data' ][ 'contacts' ];

					var critContacts = [];

					for( var i in contacts )
					{
						var contact = contacts[ i ];

						if( contact[ 'message_count' ] >= $( '#crit_message_count' ).val() )
						{
							critContacts.push( contact );
						}
					}


					var jContact = 0;
					var contacts = [];

					function pushShowContacts( contacts_ )
					{
						for( var i = 0; i < contacts_.length; i++ )
						{
							if( jContact > 7 ) break;	
							contacts.push( contacts_[ i ] );
							jContact++;
						}
					}

					pushShowContacts( critContacts );

					var showContactNum = 9;

					for( var i = jContact; i < showContactNum; i++ )
					{
						contacts.push( { 'is_anonymous': true } )
					}

					var kContact = 0; // counter for showed contacts
					var _openDiv = "<div style='overflow: hidden'>";
					var _closeDiv = "</div>";
					var photos = _openDiv;
					var isDivClose = false;

					function addContact( i, contact )
					{
						if( isDivClose )
						{
							photos += _openDiv;	
							isDivClose = false;
						}

						if( contact[ 'is_anonymous' ] == true )
						{
							photos += "<div id='photo" + String( i ) + "' class='small-photo anonymous' style='display: none'></div>";
						}
						else
						{
							photos += "<div id='photo" + String( i ) + "' class='small-photo' style='display: none; background: url( \"" + contact[ 'info' ][ 'small_photo_url' ] + "\" )'></div>";
						}
						
						if( ( i + 1 ) % 3 == 0 )
						{
							photos += _closeDiv;
							isDivClose = true;
						}
					}

					for( var i = 0; i < showContactNum; i++ )
					{
						addContact( i, contacts[ i ] );	
					}

					if( !isDivClose )
					{
						photos += "</div>";
					}

					$( '#photos' ).html( photos );

					var i = 0;

					function showPhotoByPhoto()
					{						
						var f = function(){};
						if( i < 9 )
						{
							f = showPhotoByPhoto;
						}

						$( '#photo' + String( i ) ).show( 'slow', f );
						//$( '#photo' + String( i ) ).css( 'visibility', "visible" );
						//setTimeout( f, 500 );
						//alert( "in show" );

						i++;
					}

					showPhotoByPhoto();

				}
			);
		},
		function () 
		{
			console.info( 'Api - ошибка инициализации' );
		}
	);
}	